package cn.xc.system.controller;

import cn.xc.basic.util.AjaxResult;
import cn.xc.basic.util.PageList;
import cn.xc.system.domain.SystemDictionaryDetail;
import cn.xc.system.query.SystemDictionaryDetailQuery;
import cn.xc.system.service.ISystemDictionaryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "数据字典明细api",description = "数据字典明细CRUD")
@RestController
@RequestMapping("/systemDictionaryDetail")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;

    @GetMapping
    @ApiOperation(value = "查询所有")
    public List<SystemDictionaryDetail> findAll(){
        return systemDictionaryDetailService.findAll();
    }

   /* @GetMapping("/{id}")
    @ApiOperation(value = "查询单个对象")
    public SystemDictionaryDetail findOne(@PathVariable("id") Long id){
        return  systemDictionaryDetailService.findById(id);
    }*/
    @GetMapping("/{types_id}")
    @ApiOperation(value = "查询单个对象")
    public List<SystemDictionaryDetail> findO(@PathVariable("types_id") Long types_id){
        return  systemDictionaryDetailService.findO(types_id);
    }

    @PostMapping
    @ApiOperation(value = "分页查询")
    public PageList<SystemDictionaryDetail> queryPage(@RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery){
        return systemDictionaryDetailService.queryPage(systemDictionaryDetailQuery);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public AjaxResult del(@PathVariable("id") Long id){
        try{
            systemDictionaryDetailService.del(id);
            return new AjaxResult();
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }
    @PatchMapping
    @ApiOperation(value = "批量删除")
    public AjaxResult patchDel(@RequestBody List<Long> ids){
        try{
            systemDictionaryDetailService.patchDel(ids);
            return new AjaxResult();
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    @ApiOperation(value = "添加和修改")
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        try{
            if(systemDictionaryDetail.getId()==null){
                systemDictionaryDetailService.add(systemDictionaryDetail);
            }else{
                systemDictionaryDetailService.update(systemDictionaryDetail);
            }
            return new AjaxResult();
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }


}
